package com.smart.community.property.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.community.property.entity.MeterReading;
import com.smart.community.property.mapper.MeterReadingMapper;
import com.smart.community.property.service.IMeterReadingService;

import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * 表读数服务实现
 * @author Wu.Liang
 * @since 2024-12-21
 */
@Slf4j
@Service
public class MeterReadingServiceImpl extends ServiceImpl<MeterReadingMapper, MeterReading> 
    implements IMeterReadingService {

    @Override
    public MeterReading getLatestReadingByHouseholdId(Long householdId, Integer meterType) throws Exception {
        return this.baseMapper.selectLatestReadingByHouseholdId(householdId, meterType);
    }

    @Override
    public List<MeterReading> getAbnormalReadings(Long communityId, Integer meterType, LocalDate date) throws Exception {
        return this.baseMapper.selectAbnormalReadings(communityId, meterType, date);
    }

    @Override
    public IPage<MeterReading> getMeterReadingPage(Page<MeterReading> page, Long householdId, Integer meterType, Integer readingStatus) throws Exception {
        return this.baseMapper.selectMeterReadingPage(page, householdId, meterType, readingStatus);
    }

    @Override
    @GlobalTransactional
    public boolean batchInsertMeterReadings(List<MeterReading> readings) throws Exception {
        return this.baseMapper.batchInsertMeterReadings(readings) > 0;
    }
}
